Modern computer operating systems multitask by running each thread (the part or parts of an application that actually run) for a little while (often much less than approximately one second), then switching to another thread for a little while. The overall appearance to a human using the computer is the illusion that all (or many) of the threads are running at the same time.
Each processor's attention can switch from one thread to the next thread for one of two reasons. The reasons are due to a “voluntary” context switch out or an “involuntary” context switch out.
A thread is voluntarily switched out by the processor if the switch out is performed as the result of a specific act committed by the thread. For example, if the thread chooses to wait for a keystroke, the thread can make no more forward progress until a key is pressed, and so the processor will switch out the thread and will switch in another thread (which then runs until that thread switches out for some reason).
An involuntary switch out of a thread is any switch that is not voluntary. An involuntary switch out can happen for a number of reasons. For example, if the thread has been running continuously for a long time, the processor may decide to switch to another thread due to fairness, or to make sure that the running thread does not completely monopolize the processor's time.
The problem with involuntary context switches is that they can easily interrupt a thread during a critical time. For example, if a particular thread happens to be performing an operation crucial to the forward progress of other threads (perhaps the particular thread is holding an important lock or other resource), then switching to another thread could severely reduce performance. Delaying the involuntary context switch until the shared resource is released would benefit all threads that need to access the shared resource. Unfortunately, the operating system has no way to know when the running thread is in one of the critical regions. A critical region is a sequence of instructions that is executed by a thread (process) in a program without interference so that the thread can atomically manipulate shared data. Since the operating system does not know if a thread is in a critical region, the operating system can sometime involuntarily switch out the thread while it is in the critical region. As a result, overall program performance is limited unnecessarily.
Therefore, there is a continuing need to improve and enhance the performance of current methods for preemption control.